
import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.TiledLayer;

public class BomberCanvas extends GameCanvas {

    boolean done = false;
    int width = 251;
    int height = 340;
    int mapNo = 1;
    GameManager manager;

    protected BomberCanvas() throws IOException, Exception {
        super(false);
        manager = new GameManager();
        System.out.println(this.getHeight()+"NNNNNNNNNNNNN");

    }

    public void paint(Graphics g) {
        if (!done) {
            if (manager != null) {
                try {
                    manager.draw(g);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                manager.paint(g, 0, 0);

            } else {
                //Game over
            }
        }
    }
    public void refresh(){
        //if not game over
//        if(!manager.)
        manager.move();
        paint(getGraphics());
        flushGraphics();
    }
    public void check_key(){
        int keyState = getKeyStates();
        if((keyState& LEFT_PRESSED)!=0){
            manager.left();
        }else if((keyState& RIGHT_PRESSED)!=0){
            manager.Right();
        }else if((keyState& UP_PRESSED)!=0){
            manager.Up();
        }else if((keyState& DOWN_PRESSED)!=0){
            manager.Down();
        }else if((keyState& FIRE_PRESSED)!=0){
            try {
                manager.PlaceBomb();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }else{
            manager.bomber.StopMove();
        }
    }
    public void flushKey(){
        getKeyStates();
    }
}
